@extends('layouts.default') @section('main')
<link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/themes/default/default.css" />
<link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.css" />
<script src="{{URL::asset('js/')}}/kindeditor-4.1.7/kindeditor.js" type="text/javascript"></script> 
<script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/lang/zh_CN.js"></script> 
<script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.js"></script>
<script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
<script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
<script src="{{URL::asset('js/My97DatePicker/')}}/WdatePicker.js"></script> 
<script>
KindEditor.ready(function(K) {

		var editor1 = K.create('#activity_content,#activity_description', {
			uploadJson: "{{url('kindedit/upload')}}",
			fileManagerJson: "{{url('kindedit/manager')}}",
			allowFileManager: true,
			afterBlur: function() {
				this.sync();
			},
			items: ['source', '|', 'undo', 'redo', '|', 'cut', 'copy', 'paste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', 'image', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|']
		});
		
});
</script>
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="{{url('activityprojectvideo/index')}}"
				class="tip-bottom">活动视频管理</a> <a href="#" class="current">新增活动视频</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span9">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
						<h5>新增活动视频</h5>
					</div>
					<div class="widget-content nopadding">
						<form action="{{url('activityprojectvideo/insert')}}" method="post"
							class="form-horizontal" id="activityForm">

                            <div class="control-group" id="activity_type">
                                <label class="control-label"><span class="redD">*</span>活动类型 :</label>
                                <div class="controls">
                                    <select name="activity_type" class="span11" id="activity_type">
                                        <option value="">请选择</option>
                                        @foreach($activity_type as $v)
                                            <option is_roadshow="{{$v->is_roadshow}}" is_activity="{{$v->is_activity}}" value="{{$v->code}}">{{$v->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="control-group" id="activity_id" style="display: none">
								<label class="control-label">活动名称 :</label>
								<div class="controls">
									<select name="activity_id" class="span11" id="activity">
									<option value="">请选择</option>
										{{--@foreach($activities as $activity)--}}
					                  {{--<option value="{{$activity->id}}">{{$activity->subject}}</option>--}}
					                  	{{--@endforeach--}}
					                </select>
								</div>
							</div>
							<div class="control-group" id="project_id" style="display: none">
								<label class="control-label">项目名称 :</label>
								<div class="controls">
									<select name="project_id" class="span11" id="project">
									<option value="">请选择</option>
					                </select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">视频地址 :</label>
								<div class="controls">
									<input type="text" class="span11" name="app_path"
										placeholder="视频地址" />
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">APP视频地址 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="app_path"--}}
										{{--placeholder="APP视频地址" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>标题 :</label>
								<div class="controls">
									<input type="text" class="span11" name="subject"
										placeholder="标题" />
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">副标题 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="title"--}}
										{{--placeholder="副标题" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>视频图片 :</label>
								<div class="controls">
									<input type="hidden" class="span11" name="image"
										placeholder="视频图片" />
                                    <img src="" width="120px" name="image" height="120px"/>

                                    <a href="javascript:void(0);" id="uploadPhotoBtn"   onclick="javascript:openBrowse('uploadPhotoBtn','uploadPhoto');">点击上传(图片大小不小于h:876像素×w:1440像素)</a>
                                        <input type="file" id="uploadPhoto" style="display:none" name="myfile" size="10" onchange="fileUpload('uploadPhoto','image')"/>
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">发布时间 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="pubdate" onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"--}}
										{{--placeholder="发布时间" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label">描述 :</label>
								<div class="controls">
									<textarea class="span11"  name="description" ></textarea>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>内容 :</label>
								<div class="controls">
									<textarea id="activity_content" name="content" style="width: 450px; height: 240px;"></textarea>
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">二维码地址 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="qrcode"--}}
										{{--placeholder="二维码地址" />--}}
								{{--</div>--}}
							{{--</div>--}}
							{{--<div class="control-group">--}}
								{{--<label class="control-label">播放量 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="views"--}}
										{{--placeholder="播放量" />--}}
								{{--</div>--}}
							{{--</div>--}}
							{{--<div class="control-group">--}}
								{{--<label class="control-label">视频时长 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="times"--}}
										{{--placeholder="视频时长" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label">点赞 :</label>
								<div class="controls">
									<input type="text" class="span11" name="likes"
										placeholder="点赞" />
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">点击量 :</label>
								<div class="controls">
									<input type="text" class="span11" name="click_views"
										placeholder="点击量" />
								</div>
							</div>
                            <div class="control-group">
                                <label class="control-label">排序(默认50，可修改) :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="sort"
                                           placeholder="排序(默认50，可修改)" value="50" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>是否热门 :</label>
                                <div class="controls">
                                    <select  name="hot" class="span11" >
                                        <option value="">请选择</option>
                                        <option value="1">热门</option>
                                        <option value="0">不热门</option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>是否置顶 :</label>
                                <div class="controls">
                                    <select  name="top" class="span11" >
                                        <option value="">请选择</option>
                                        <option value="1">置顶</option>
                                        <option value="0">不置顶</option>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">是否精彩 :</label>
                                <div class="controls">
                                    <select  name="wonderful" class="span11" >
                                        <option value="">请选择</option>
                                        <option value="1">精彩</option>
                                        <option value="0" selected>不精彩</option>
                                    </select>
                                </div>
                            </div>

                            <div id="user" style="display: none;">
                                <div class="control-group">
                                    <label class="control-label">用户姓名或手机号的一部分供模糊搜索 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="user_search" value="" placeholder="输入用户姓名或手机号的一部分，按下Enter键，搜索结果将出现在下面的多选框中，供选择" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">视频拥有人 :</label>
                                    <div class="controls">
                                        <select name="uid" id="uid">
                                            <option value="">请按上面输入框的说明生成选项</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">视频关键字 :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="tag"
                                           placeholder="视频关键字,若有多个关键字，则以逗号隔开" />
                                </div>
                            </div>


                                <div class="form-actions">
								<button type="button" id="doSave" class="btn btn-success">保存</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>

<script>

    $("input[name='user_search']").keydown(function(event) {
        if (event.which == "13"){
            var param = {};
            param['user_search'] = $(this).val();
            ajaxRequest(param, '/project/user-search', function (data) {
                if (data.status) {
                    var html = '<option value="">请选择</option>';
                    $.each(data.message, function (i, n) {
                        if(n.realname){
                            html += "<option value='" + n.uid + "'>" + n.realname + "</option>";
                        }else{
                            html += "<option value='" + n.uid + "'>" + n.nickname + "</option>";
                        }
                    });
                    $("#uid").html(html);
                    alert('恭喜，已经生成选项,请选择所需要的用户');
                } else {
                    var html = '<option value="">请按上面输入框的说明生成选项</option>';
                    $("#uid").html(html);
                    alert(data.message);
                }
            });
        }
    });

$("select[name=activity_type]").change(function(){
    var is_roadshow=$(this).find("option:selected").attr('is_roadshow');
    var is_activity=$(this).find("option:selected").attr('is_activity');
    var activity_type=$(this).val();

    if(is_roadshow==1 && is_activity==1){
        $("#activity_id").show();
        $("#project_id").show();
        $("#user").hide();
    }

    if(is_activity!=1 && is_roadshow!=1){
        $("#activity_id").hide();
        $("#project_id").hide();
        $("#user").hide();

    }

    if(is_activity==1 && is_roadshow!=1){
        $("#activity_id").show();
        $("#project_id").hide();
        $("#user").hide();
    }

    if(is_activity==0 && is_roadshow==0){
        $("#user").show();
    }

    param={};
    param['activity_type'] = activity_type;

    ajaxRequest(param,"{{url('activityprojectvideo/search-activity')}}",function(data){
        if(data.status){
            var html = '<option value="">请选择</option>';
            $.each(data.message, function(i, n) {
                html += "<option value='"+n.id+"'>"+n.subject+"</option>";
            });
            $("#activity").html(html);
        }else{
            var html = '<option value="">请选择</option>';
            $("#activity").html(html);

        }
    });

})



$("#doSave").click(function(){
    $(this).attr('disabled','disabled');

    ajaxRequest($('#activityForm').serializeArray(),$('#activityForm').attr('action'),function(data){
		if(data.status){
            alert(data.message);
            window.location.href = data.forwardUrl;
		}else{
            $("#doSave").removeAttr('disabled');
            alert(data.message);
		}
	});
});
$("#activity").change(function() {
	$("#project").empty();
	$.post("{{url('activityprojectvideo/activityprojects')}}", {
		aid: $(this).val()
	}, function(data) {
		if (data.status) {
			var html = '<option value="">请选择</option>';
			$.each(data.message, function(i, n) {
				html += "<option value='"+n.id+"'>"+n.subject+"</option>";
			});
			$("#project").html(html);
		}
	}, 'json');
});
</script>
@stop
